package lab02.test24;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.util.*;
/**
 * Created by 婷婷 on 2017/11/1.
 */
public class Test24 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入第一个日期，格式如20100310:");
        String data = scanner.nextLine();

        //从输入的数据中找出年月日的分界
        String year =data.substring(0,4);
        String month =data.substring(4,6);
        String day =data.substring(6);

        Calendar calendar = Calendar.getInstance();
        //设置年月日
        calendar.set(Integer.parseInt(year),Integer.parseInt(month),Integer.parseInt(day));

        Date date1 = calendar.getTime();
        System.out.println("请输入第二个日期，格式如20100310:");
        data = scanner.nextLine();

        year =data.substring(0,4);
        month =data.substring(4,6);
        day =data.substring(6);

        calendar.set(Integer.parseInt(year),Integer.parseInt(month),Integer.parseInt(day));

        Date date2 = calendar.getTime();
        long SubDay = (date1.getTime()-date2.getTime())/(24*60*60*1000);
        if (SubDay < 0)    SubDay = (date2.getTime()-date1.getTime())/(24*60*60*1000);
        System.out.println("两个日期之间相差"+SubDay+"天");
    }
}
